/*
 * @Author: wjc
 * @Date: 2025-07-29 17:31:45
 * @LastEditors: wjc
 * @LastEditTime: 2025-10-28 17:25:08
 * @Description:
 */
import type { Pinia } from 'pinia'

import type { App } from 'vue'

import { router } from '#/router'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

let pinia: Pinia

export function setupStores(app: App) {
  pinia = createPinia()
  pinia.use(piniaPluginPersistedstate)
  pinia.use((s) => {
    s.store.$router = markRaw(router)
  })
  app.use(pinia)
}

export function resetAllStores() {
  if (!pinia) return
  const allStores = (pinia as any)._s
  for (const [_key, store] of allStores) {
    store.$reset()
  }
}

export * from './modules'
